<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__PUBLIC__/admin/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="__PUBLIC__/admin/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/action.js"></script>
    <script type="text/javascript" src="__PUBLIC__/plugins/xheditor/xheditor-1.2.1.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/plugins/xheditor/xheditor_lang/zh-cn.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jCalendar.js"></script>

    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/kindeditor/kindeditor.js"></script>
    <script charset="utf-8" src="__PUBLIC__/admin/kindeditor/lang/zh_CN.js"></script>
    <script language="javascript">
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('#intro');
            // editor = K.create('#editor_id');多个
        });
    </script>
    <style>
        #imageContainer img {
            margin: 0 5px 5px 0;
        }

        .targetImage {
            position: relative;
            float: left
        }

        .targetImage span {
            display: block;
            position: absolute;
            width: 30px;
            height: 30px;
            top: 0;
            background-color: #000;
            color: #fff;
            text-align: center;
            line-height: 30px;
            cursor: pointer
        }
    </style>
    <title>{$title}</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> {$modules} <span
        class="c-gray en">&gt;</span> {$title}
</nav>
<div class="page-container">
    <form class="form form-horizontal" id="horizontal" action="{:U('saveGoods')}" method="post" onsubmit="return ac_from();"
          enctype="multipart/form-data">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品图片：</label>
            <div class="formControls col-xs-8">
                <input id="fileInput" type="file" name="file" id="file" value="{$detail.cover}" style="display: none;" multiple>
                <div style="border: 1px solid #dfdfdf; padding: 5px; overflow-y: scroll; min-height: 160px" id="imageContainer">
                    <?php if(!empty($detail['images'])){ foreach($detail['images'] as $v){ ?>
                    <div class='targetImage'><img width='250' height='150' src="__DATA__/<?php echo $v; ?>"><span>X</span></div>
                    <?php }} ?>
                </div>
                <span style="display: block; margin-top: 10px; color: #666">
                    <span style="display: inline-block; background-color:#ccc;padding: 3px 10px; cursor: pointer; Zcolor: #000;"
                          id="chooseImages">选择图片</span>
                    &nbsp;&nbsp;&nbsp;宽750 x 高475， 单图大小限制在1M以内，最多五张图片
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品分类：</label>
            <div class="formControls col-xs-8">
                <select name="cate_id" id="">
                    <volist name="cate" id="vo">
                        <option value="{$vo.id}"
                        <?php if($detail['cate_id'] == $vo['id']){
                        echo "selected";
                        } ?>
                        >
                        {$vo.name}
                        </option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品名称：</label>
            <div class="formControls col-xs-8">
                <input type="text" class="input-text" placeholder="商品名称" name="name" value="{$detail.name}"
                       required="required">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>兑换所需积分：</label>
            <div class="formControls col-xs-8">
                <input type="text" class="input-text" placeholder="数字" name="point" id="point" value="{$detail.point}"
                       required="required">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>库存：</label>
            <div class="formControls col-xs-8">
                <input type="text" class="input-text" placeholder="数字" name="in_stock" id="in_stock"
                       value="{$detail.in_stock}" required="required">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品详情：</label>
            <div class="">
                <textarea id="intro" name="content" style="width:700px;height:500px;"/>{$detail.content}</textarea>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">排序：</label>
            <div class="formControls col-xs-8">
                <input type="text" class="input-text" placeholder="排序，选填，数字越小排名越前" name="sort" value="{$detail.sort}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">是否上架：</label>
            <div class="formControls col-xs-8">
                <input type="radio" name="is_show" value="0" id="is_show_0" <?php if($detail['is_show'] == 0){ echo 'checked="checked"'; } ?>> <label for="is_show_0">下架</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="is_show" value="1" id="is_show_1" <?php if($detail['is_show'] != 0){ echo 'checked="checked"'; } ?>> <label
                    for="is_show_1">上架</label>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">是否推荐：</label>
            <div class="formControls col-xs-8">
                <input type="radio" name="recommend" value="0" id="recommend_0" <?php if($detail['recommend'] != 1){ echo 'checked="checked"'; } ?>> <label for="recommend_0">不推荐</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="recommend" value="1" id="recommend_1" <?php if($detail['recommend'] == 1){ echo 'checked="checked"'; } ?>> <label for="recommend_1">推荐</label>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" name="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                <input type="hidden" name="id" value="{$detail.id}">
                <input type="hidden" name="images" value="<?php if(!empty($detail['images'])){ echo implode(',', $detail['images']); }  ?>">
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="__PUBLIC__/admin/js/product.js"></script>
<script>
    $(function () {
        //初始化编辑器
        $('#content').xheditor({
            skin: 'nostyle',
            upImgUrl: '{:U("Upload/xheditor")}'
        });

        // 图片选择
        $("#chooseImages").click(function () {
            $("#fileInput").click();
        });

        // 图片显示
        $("#fileInput").change(function () {
            var imageObjs = $("#fileInput")[0].files;
            for (var i = 0; i < imageObjs.length; i++) {
                var formdata = new FormData();
                formdata.append('file', imageObjs[i]);
                var xhr = new XMLHttpRequest();
                xhr.open("post", "/index.php/Admin/Point/goodsImageUpload", false);
                xhr.send(formdata);
                $("#imageContainer").append("<div class='targetImage'><img width='250' height='150' src='/Data/"+xhr.responseText+"'><span>X</span></div>")
            }
        });
        $(".targetImage > span").live('click', function () {
            $(this).parents('.targetImage').remove();
        })
    })

    function ac_from() {
        // 商品图片处理
        var images = [];
        $(".targetImage > img").each(function(){
            images.push($(this).attr('src'));
        })
        $("input[name='images']").val(images.join(','));
    }
</script>

</body>
</html>
